package com.ztf.sm;

import com.ztf.sm.util.SM2KeyPair;
import com.ztf.sm.util.SM2Util;
import com.ztf.sm.util.Sm2Utils;
import com.ztf.sm.util.Sm4Util;

import java.security.KeyPair;
import java.security.NoSuchAlgorithmException;

public class TestSm2AndSm4 {
    public static void main(String[] args) throws Exception {
     //生成SM2公钥和私钥
     TestSm2AndSm4 testSm2AndSm4 = new TestSm2AndSm4();
        SM2KeyPair keyPair = testSm2AndSm4.genPUPRkeySm2();
     //生成SM4密钥
     String sm4Key =  Sm4Util.generateKey();
//     System.out.println("sm4Key"+sm4Key);
//     String  strEncry = Sm4Util.encryptEcb(sm4Key, "你好中国!");
//     System.out.println("加密内容"+strEncry);
//     String content =Sm4Util.decryptEcb(sm4Key,strEncry);
//     System.out.println("content"+content);
     //对SM4密钥进行加解密,
     //Sm2Utils.decrypt()
      String strEn = SM2Util.encrypt(keyPair.getPublicKey(),sm4Key);
        System.out.println("SM2加密的密钥："+strEn);
        String StrDe = SM2Util.decrypt(keyPair.getPrivateKey(),strEn);
        System.out.println("SM2解密的密钥："+StrDe);
    }

    //生成sm2私钥和秘钥k
    public SM2KeyPair genPUPRkeySm2(){
        SM2KeyPair keyPair =null;
        try {
            keyPair = SM2Util.generateSm2KeyPair();

        } catch (Exception e) {
            e.printStackTrace();
        }
        return keyPair;
    }
}
